package com.neusoft.elmboot.service.impl;

import com.neusoft.elmboot.mapper.ReviewMapper;
import com.neusoft.elmboot.po.Review;
import com.neusoft.elmboot.service.ReviewService;
import com.neusoft.elmboot.service.ex.DataNotFoundException;
import com.neusoft.elmboot.service.ex.DeleteException;
import com.neusoft.elmboot.service.ex.InsertException;
import com.neusoft.elmboot.service.ex.UpdateException;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ReviewServiceImpl implements ReviewService {
    @Autowired
    private ReviewMapper reviewMapper;
    @Override
    public int insertReview(Review review) {
        int result = reviewMapper.insertReview(review);
        if(result < 0){
            throw new InsertException("插入评论失败!");
        }
        return result;
    }
    @Override
    public int deleteReview(Review review) {
        int result = reviewMapper.deleteReview(review);
        if(result < 0){
            throw new DeleteException("删除评论失败!");
        }
        return result;
    }
    @Override
    public int updateReview(Review review) {
        int result = reviewMapper.updateReview(review);
        if(result < 0){
            throw new UpdateException("更新评论失败!");
        }
        return result;
    }
    @Override
    public List<Review> selectReview(Integer businessId) {
        List<Review> reviews = reviewMapper.selectReview(businessId);
        if(reviews == null){
            throw new DataNotFoundException("没有找到评论数据!");
        }
        return reviews;
    }
}
